Rails.application.routes.draw do
  namespace :front do
    get 'welcome/index'
  end


  mount WeixinRailsMiddleware::Engine, at: "/"
  root 'front/welcome#welcome'
  get '/index' => 'front/welcome#welcome'
  get '/admin' => "admin/sessions#new"
  post '/join_us' => "front/welcome#join_us"
  get '/restaurants' => 'restaurants/sessions#new'
  match '/notify/pay' => 'mobile/pay#index',via: [:get, :post],defaults: {fomart: 'json'}

  namespace :mobile,defaults: {format: 'json'} do
    namespace :services do
      resources :sms_service do
        match :send_notification, on: :collection,via: [:post,:get,:options]
      end  
    end  
    namespace :weixin do
        resources :restaurants do
            resources :food_types
            resources :products
            resources :cars,only: [:index,:show] do
                get :add,on: :collection
                get :remove,on: :collection
                get :clear,on: :collection
            end    
            resources :orders,only: [:new,:index,:create] do
              get :new_order,on: :collection
              get :cancel,on: :collection
              get :finish,on: :collection
              get :wx_pay,on: :member
              get :cancel_pay,on: :collection,defaults: {format: 'html'}
            end              
        end  
        get '/new_order' => 'orders#new_order',defaults: {format: 'html'}
        get '/welcome/:restaurant_id/:table_no'  => 'weixin#welcome',defaults: {format: 'html'}
    end
    namespace :apps do
      resources :foods do
        get :print,on: :member
        get :pay,on: :member
      end  
    end  
  end  
  namespace :admin do
    resources :sessions,only: [:new,:create] do
      get :logout,on: :collection
    end   
    resources :restaurants  do
      resources :printers,except: [:show]
    end 
  end  
  namespace :restaurants do
    resources :sessions,only: [:new,:create] do
       get :logout,on: :collection
    end  
    
    get '/info/show' => 'info#show'
    get '/info/bulletion' => 'info#bulletion'
    get '/info/qrcode' => 'info#qrcode'
    get '/info/edit' => 'info#edit'
    put '/info/update' => 'info#update'
    get '/info/edit_bulletion' => "info#bulletion_edit"
    put '/info/update_bulletion' => "info#update_bulletion"
    get '/welcome' => 'restaurants#welcome'
    get '/new_password' => 'restaurants#new_password'
    put '/update_password' => 'restaurants#update_password'
    
    resources :printers,except: [:show]
    resources :messages
    resources :orders do
      get :pay,on: :member
      get :print_order,on: :member
      get :finish_order,on: :member
      delete :cancel,on: :member
    end  
    get '/charts/sellers' => 'charts#sellers'
    get '/charts/orders' => 'charts#orders'
    resources :foods do
      put :unpublished,on: :member
      put :published,on: :member
    end  
    resources :food_types
  end  
end
